import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

// 获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
// 修改原型对象中的push方法
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}

const routes = [
	{
		path: '/login',
		name: 'login',
		component: () => import('../views/login/LoginView.vue')

	},
	{
		path: '/',
		name: 'home',
		component: () => import('../views/home/HomeView.vue'),
		children: [
			{
				path:'',
				redirect:'/home/homepage'
			},
			{
				path: "/home/category1/1005000",
				name: "居家",
				component: () => import('../views/category1/CategoryOneViews.vue'),
			},
			{
				path: "/home/category1/1005002",
				name: "美食",
				component: () => import('../views/category1/CategorymeisViews.vue'),
			},
			{
				path: "/home/category1/1010000",
				name: "服饰",
				component: () => import('../views/category1/CategoryfushiViews.vue'),
			},
			{
				path: "/home/category1/1011000",
				name: "母婴",
				component: () => import('../views/category1/CategorymuyViews.vue'),
			},
			{
				path: "/home/category1/1013001",
				name: "个护",
				component: () => import('../views/category1/CategorygehViews.vue'),
			},
			{
				path: "/home/category1/1019000",
				name: "严选",
				component: () => import('../views/category1/CategoryyanxViews.vue'),
			},
			{
				path: "/home/category1/1043000",
				name: "数码",
				component: () => import('../views/category1/CategoryshumViews.vue'),
			},
			{
				path: "/home/category1/109243029",
				name: "运动",
				component: () => import('../views/category1/CategoryyundViews.vue'),
			},
			{
				path: "/home/category1/19999999",
				name: "杂项",
				component: () => import('../views/category1/CategoryzaxViews.vue'),
			},
			{
				path: "/home/homepage",
				name: "homepage",
				component: () => import('../views/homepage/HomePage.vue'),
			},
			{
				path: "/home/category1",
				name: "category1",
				component: () => import('../views/category1/CategoryOneViews.vue'),
			},
			{
				path: "/home/category2",
				name: "page2",
				component: () => import('../views/category2/CategoryTwoViews.vue'),
			},
			{
				path: "/home/order",
				name: "page3",
				component: () => import('../views/order/OrderView.vue'),
				children:[
					// 重定向
					{
						path:"",
						redirect:"/order/personal"
					},
					{
						path: '/order/personal',
						name: 'personal',
						component: () => import('../views/personal/PersonalView.vue'),
					},
					{
						path: '/order/myorder',
						name: 'myorder',
						component: () => import('../views/myorder/MyorderView.vue'),
					},
				]
			},
			{
				path: "/home/details",
				name: "page4",
				component: () => import('../views/details/DetailView.vue'),
			},
			{
				// 购物车
				path:"/cart",
				name:"cart",
				component: () => import('../views/cart/CartView.vue')
			},
			{
				// 下单页
				path:"checkout",
				name:"checkout",
				component: () => import('../views/checkout/CheckoutView.vue')
			}
		]
	}
]

const router = new VueRouter({
	routes
})

export default router
